package com.rul.mars.order.controller;

import com.rul.mars.common.api.CommonPage;
import com.rul.mars.common.api.CommonResult;
import com.rul.mars.mbg.domain.DeliveryParam;
import com.rul.mars.mbg.domain.OrderDetail;
import com.rul.mars.mbg.domain.OrderQueryParam;
import com.rul.mars.mbg.model.Order;
import com.rul.mars.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商家订单服务接口
 *
 * @author RuL
 */
@Api(tags = "MerchantOrderController", description = "商家订单服务接口")
@RestController
@RequestMapping("/merchant/order")
public class MerchantOrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 商家发货
     *
     * @param param 发货所需参数信息
     * @return 操作结果
     */
    @ApiOperation("商家发货")
    @PostMapping("/delivery")
    public CommonResult delivery(@RequestBody DeliveryParam param) {
        boolean success = orderService.delivery(param);
        if (success) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    /**
     * 按条件查询订单
     *
     * @param queryParam 查询条件
     * @return 查询结果
     */
    @ApiOperation("按条件查询订单")
    @GetMapping("/list")
    public CommonResult<CommonPage<Order>> listOrder(@RequestBody OrderQueryParam queryParam,
                                                     @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        List<Order> orderList = orderService.listOrder(queryParam, pageNum, pageSize);
        //转为分页信息
        CommonPage<Order> orderPage = CommonPage.restPage(orderList);
        return CommonResult.success(orderPage);
    }
}
